package util;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

public class StringUtil {
		public static String toUTF8(String isoString) {
			  String utf8String = null;
			  if (null != isoString && !isoString.equals("")) {
			   try {
			    byte[] stringBytesISO = isoString.getBytes("ISO-8859-1");
			    utf8String = new String(stringBytesISO, "UTF-8");
			   }
			   catch(UnsupportedEncodingException e) {	   
				   System.out.println("UnsupportedEncodingException is: " + e.getMessage());
				   utf8String = isoString;
			   }
			  } else {
				  utf8String = isoString;
			  }
			  return utf8String;
		}
		
		public static Boolean isNumber(char c)
	    {
	        String str = "0123456789";
	        int i;
	        for (i = 0; i < str.length(); i++)
	        {
	            if (c == str.charAt(i))
	                i = str.length();
	        }
	        if (i == str.length() + 1)
	            return true;
	        return false;
	    }
		
		public static String isNull(String a){
			
			if(a == null){
				a = "";
			}
			return a;
		}
		
		public static String toTrim (String textTrim){
			String a = null ;
			if (null != textTrim && !textTrim.equals("")) {
				try {
					String temp = textTrim;
					String[] ten = null;
					String b = "";
					ten = temp.split(" ");
					for(int i =0; i < ten.length; i++){
						ten[i].replace(" ", "");
						if(!ten[i].equals("")){
							b+= ten[i] + " ";
						}
					}
					a = b;
				}
				catch(Exception e) {	   
						   System.out.println("UnsupportedEncodingException is: " + e.getMessage());
						   a = textTrim;
				 }
			}else{
				a = textTrim;
			}
			return a;
		}
}
